#include <iostream>

void guessthenumber()
{
	int target_number;
	target_number=rand()%50+1;

	int guess_number;

	int chances = 0;

	bool game_flag = true;
	
	std::cout<<"game start"<<std::endl;
	std::cout<<"you have four chances"<<std::endl;
	std::cout<<std::endl;
	
	
	while(game_flag)
	{
		std::cout<<"Please enter a number from 1 to 50: "<<std::endl;
		std::cin>>guess_number;
		if(guess_number>50 || guess_number<1)
		{
		std::cout<<"The number is out of range"<<std::endl;
		std::cout<<"Please enter a number from 1 to 50: "<<std::endl;
		continue;
		}
		else if(guess_number == target_number)
		{
		std::cout<<"Congratulations, that's right"<<std::endl;
		break;
		}
		else
		{
		std::cout<<"Unfortunately, that's wrong"<<std::endl;
			if(guess_number>target_number)
			{
			std::cout<<"the target is smaller"<<std::endl;
			}
			else if(guess_number<target_number)
			{
			std::cout<<"the target is bigger"<<std::endl;
			}
		chances++;
		if(chances == 4)
		{
			game_flag = false;
		std::cout<<"the target is : "<<target_number<<std::endl;
		std::cout<<"you have no chances, game over"<<std::endl;

		}

		}

	}


}
